<?php
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = "";
}  

$v_reason = "";
if(isset($_REQUEST['txt_reason'])){
	$v_reason = _replace_bad_char($_REQUEST['txt_reason']);
} 

$v_record_id = "";
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = $_REQUEST['hdn_record_id'];
}
$v_work = "";
if(isset($_REQUEST['hdn_work'])){
	$v_work = $_REQUEST['hdn_work'];
}
$v_work_date = "";
if(isset($_REQUEST['txt_work_date'])){
	$v_work_date= $_REQUEST['txt_work_date'];
} 
//---------------hieudt #82 101108-----------------------
$kq_tl = _TRINH_KY;
$is = false;
//kiem tra phong ban
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];//Lay loai thu tuc
$arr_staff_appro = _get_item_attr_by_id($_SESSION['arr_all_staff'],$v_leader, 'unit_id' );
$_arr_unit_code =  explode(",",$kq_tl); //ham cat chuoi luu vao mang $_arr_unit_code 
// var_dump ($_arr_unit_code);
$j = 0;	
$arr_unit_id = array();			
foreach($_SESSION['arr_all_unit'] as $v_unit)
{
	for($i = 0 ; $i < sizeof($_arr_unit_code) ; $i ++)
	{
		if($v_unit['code'] == $_arr_unit_code[$i])
		{
			$arr_unit_id[$j] = $v_unit['id'] ;
			$j ++;
		}						
	}
}  

$v_size_unit = sizeof($arr_unit_id);
$is = false;
if ($v_size_unit >=1)
{
	for ($i = 0; $i <$v_size_unit && $is == false ; $i ++)
	{
		if($arr_staff_appro == $arr_unit_id[$i])
			 $is = true;
	}
}
		
if ($is == true)
{
	/*trinh lan dau*/
	if ( $v_work == 'TRINH_LD_PHONG_LAN_DAU') {
		$v_work = 'TRINH_LD_VP_LAN_DAU';
	}
	if ( $v_work == 'LD_PHONG_TRALAI') {
		$v_work = 'LD_VP_TRALAI';
	}
	/*trinh lai*/
	if ( $v_work == 'TRINH_LD_PHONG_LAN_SAU') {
		$v_work = 'TRINH_LD_VP_LAN_SAU';
	}
	/*trinh lan 2*/
	if ($v_work == 'TRINH_LD_PHONG_DUYET_LAN_HAI') {
		$v_work = 'TRINH_LD_VP_DUYET_LAN_HAI';
	}
	if ($v_work == 'TRINH_LD_PHONG') {
		$v_work = 'TRINH_LD_VP';
	}
	if ( $v_work == 'TRINH_LD_PHONG') {
		$v_work = 'TRINH_LD_VP';
	}
	/*cap phep*/
	if ( $v_work == 'LD_PHONG_CAPPHEP' ||  $v_work == 'LD_COQUAN_CAPPHEP') {
		$v_work = 'LD_VP_CAPPHEP';
	}
	if ($v_work == 'LD_PHONG_TUCHOI'||  $v_work == 'LD_COQUAN_TUCHOI') {
		$v_work = 'LD_VP_TUCHOI';
	}			
}		
//---------------end hieudt #82 101108---------------------
if(_is_sqlserver()){
	$v_worker_id = $_SESSION['staff_id'];
	$sql = "Exec Onegate_RecordWorkSystemUpdate " ;
	$sql = $sql . "'" . $v_record_id . "'";
	$sql = $sql . "," . $v_worker_id;
	$sql = $sql . ",'" . $v_work . "'";
	$sql = $sql . ",'" . _ddmmyyyy_to_yyyymmdd($v_work_date) . "'" ;
	$sql = $sql . "," . $_ISA_AUTOMATIC_UPDATE_WORK_LIST;
	$sql = $sql . ",'" . $v_reason . "'" ;
	//echo $sql .'<br>' ; exit(1);
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
?>
<form action="index.php" method="post" name="f_back"> 
  <input type="hidden" name="fuseaction" value="<?php echo $fuseaction_back; ?>">
  <input type="hidden" name="fuseaction_back" value="<?php echo $fuseaction_back; ?>">
  <input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
</form> 
<Script language="javascript">
	document.forms(0).submit();
</Script> 
